package sum.Controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import sum.Dao.TeacherDao;
import sum.Entity.Student;
import sum.Service.StudentService;
import sum.Service.TeacherService;

import java.util.List;

@Controller
@RequestMapping("/teacher")
public class TeacherController {
    @Autowired
    TeacherService teacherService;
    @Autowired
    StudentService studentService;
    @RequestMapping("/addone")
    public String addone(Student student){
        teacherService.addone(student);
        return "teacher";
    }
    @RequestMapping("/delete")
    public String delete(Student student)
    {
        teacherService.deleteByName(student);
        return "teacher";
    }
    @RequestMapping("/edit")
    public String edit(Student student, Model model){
       teacherService.edit(student);
        List<Student> students = studentService.queryByClass(student.getStu_class());
        model.addAttribute("students",students);
        return "teacher";
    }
}
